<?php
session_start();
include("utils.php");
$mode = $_POST['mode'];
if($mode=='create_advertise')
{
create_ad();
}
else
{
main_content("main();");
//main();
}

############################## function to update user account starts#########################
function create_ad(){
//echo "<script>alert('123')</script>";
//print_r($_REQUEST);

if($_REQUEST['ad_type']=='banner')
{
$select_mobile_ad_image="select * from temp_image_upload where user_id = '".$_SESSION['siteuserId']."' order by image_id desc";

$exe_mobile_ad_image=mysql_query($select_mobile_ad_image);
$row_mobile_ad_image=mysql_fetch_array($exe_mobile_ad_image);

$ad_image_name=$row_mobile_ad_image['image_name'];
//echo "<script>alert('".$ad_image_name."')</script>";
mysql_query("delete from temp_image_upload where user_id = '".$_SESSION['siteuserId']."'");
}
################################ starts ################
$str_country='';
			for($i=0;$i<count($_REQUEST[country_mobile]);$i++)
			{
			if($_REQUEST[country_mobile][$i] != 0 || $_REQUEST[country_mobile][$i] != ''){
			
			if(count($_REQUEST[country_mobile])>1)
			{
				if($i==count($_POST[country_mobile])-1)
				{
					$str_country.=$_REQUEST[country_mobile][$i];
				}
				else
				{
					$str_country.=$_REQUEST[country_mobile][$i].",";
				}
			}
			else
			{
				$str_country.=$_REQUEST[country_mobile][$i];
			}
			}
			}

//echo "<script>alert('".$str_country."')</script>";
############################### ends ####################

if($_REQUEST['ad_type']=='text')
{
	$insert_create_ad="insert into create_mobile_ad set user_id = '".$_SESSION['siteuserId']."', ad_type = '".$_REQUEST['ad_type']."', ad_name = '".$_REQUEST['ad_name']."', bid_price = '".$_REQUEST['bid_price']."', ad_text = '".$_REQUEST['ad_text']."', link_to = '".$_REQUEST['destinationUrl']."', country_id = '".$str_country."'";
}
else if($_REQUEST['ad_type']=='banner')
{
	$insert_create_ad="insert into create_mobile_ad set user_id = '".$_SESSION['siteuserId']."', ad_type = '".$_REQUEST['ad_type']."', ad_name = '".$_REQUEST['ad_name']."', bid_price = '".$_REQUEST['bid_price']."', link_to = '".$_REQUEST['destinationUrl']."', country_id = '".$str_country."', ad_image = '".$ad_image_name."'";
}
mysql_query($insert_create_ad);
main_content("main();");
}
############################## function to update user account ends ############################

function main()
{
?>
<script language="JavaScript">

function create_ad()
{
	if(document.myAccountForm.bid_price.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_bidPrice').style.display='';
		document.getElementById('error_bidPrice').innerHTML="Please! Enter Bid Price.";
		return false;
	}

	if(isNaN(document.myAccountForm.bid_price.value))
	{
		if(document.getElementById('row_alert_bidPrice').style.display=='')
		{
			document.getElementById('error_bidPrice').innerHTML="Please! Enter Numeric Value As Bid Price.";
		}
		else if(document.getElementById('row_alert_bidPrice').style.display=='none')
		{
			document.getElementById('row_alert_bidPrice').style.display='';
			document.getElementById('error_bidPrice').innerHTML="Please! Enter Numeric Value As Bid Price.";
		}
		return false;
	}

	if(document.myAccountForm.ad_name.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_adName').style.display='';
		document.getElementById('error_adName').innerHTML="Please! Enter Ad Name.";
		return false;
	}

	if(document.myAccountForm.ad_type.value != 'banner')
	{
	if(document.myAccountForm.ad_text.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_adText').style.display='';
		document.getElementById('error_adText').innerHTML="Please! Enter Ad Text.";
		return false;
	}
	}

	//alert(document.myAccountForm.link_url[0].checked);
 	if(document.myAccountForm.link_url[0].checked == true)
 	{
		if(document.myAccountForm.destinationUrl.value.search(/\S/) == -1)
		{
			document.getElementById('row_alert_linkURL').style.display='';
			document.getElementById('error_adURL').innerHTML="Please! Enter The Link.";
			return false;
		}
		
		
	}

	document.myAccountForm.mode.value='create_advertise';
	document.myAccountForm.submit();
}


function show_mobile_set(id)
{
	//alert(id);
	for(var i =1; i<=4;i++)
	{
// 		if(document.getElementById('content_'+i))
// 		{
			if(i == id)
			{
				//alert('aaa');
				document.getElementById('content_'+i).style.display = 'block';	
			}
			else
			{
				document.getElementById('content_'+i).style.display = 'none';	
			}

		//}
		
	}
	
}


function show_destination_url(val)
{
//alert(val);
	if(val=='lp')
	{
		document.getElementById('link_url_existing_div').style.display='none';
		document.getElementById('link_url_lp_div').style.display='';
		document.getElementById('link_url_existing_landing_page').style.display='';
	}
	else
	{
		document.getElementById('link_url_existing_div').style.display='';
		document.getElementById('link_url_lp_div').style.display='none';
		document.getElementById('link_url_existing_landing_page').style.display='none';
		document.getElementById('show_url').style.display='none';
	}
}

function una_dis(landing_val)
{
	//alert(landing_val);
	
// 	if(document.getElementById('landing_url').value != "select")
// 	{
	//document.getElementById('txtUrl').disabled=true;
	var arr=landing_val.split("-");
	//alert(arr[0]);
	//alert(arr[1]);
	document.getElementById('show_url').style.display='';
	document.getElementById('show_url').innerHTML='<a href='+arr[1]+'>'+arr[1]+'</a>';
	//}

// 	else {
// 	document.getElementById('txtUrl').disabled=false; 
// var arr=landing_val.split("-");
// 	document.getElementById('show_url').style.display='block';
// 	document.getElementById('show_url').innerHTML=arr[1];
	//}


}
// #########################
function show_text_image()
{
	if(document.getElementById('ad_type').value=='banner')
	{
		document.getElementById('ad_text').style.display='none';
		document.getElementById('text_preview').style.display='none';
		document.getElementById('image_section').style.display='block';
		document.getElementById('preview').style.display='block';
	}
	else
	{
		document.getElementById('image_section').style.display='none';
		document.getElementById('preview').style.display='none';
		document.getElementById('ad_text').style.display='block';
		document.getElementById('text_preview').style.display='block';
	}
}

function preview_text_description_func()
{
document.getElementById("preview_text_description").value = document.getElementById("ad_text").value;
document.getElementById("preview_text_description").innerHTML= document.getElementById("ad_text").value;
document.getElementById("preview_text_description").style.display = 'block';
}

function preview_heading()
{
document.getElementById("prev_heading").value = document.getElementById("ad_name").value;
document.getElementById("prev_heading").innerHTML= document.getElementById("ad_name").value;
document.getElementById("prev_heading").style.display = 'block';
}
</script> 
<script language="javascript" src="js/ajax.js"></script>
<script language="javascript" src="js/ajaxresponse.js"></script>
<script language="javascript" src="JavaScripts/common.js"></script>
<script language="javascript" src="JavaScripts/create_ad.js"></script>
<script language="javascript" src="JavaScripts/ext-base-all.js"></script>
<script language="javascript" src="JavaScripts/TreeCheckNodeUI.js"></script>
<link href="css/global.css" rel="stylesheet" type="text/css">
<link href="css/create_ad.css" rel="stylesheet" type="text/css">
<link href="css/ext-all.css" rel="stylesheet" type="text/css">
<link href="css/ext-all.css" rel="stylesheet" type="text/css">
<link href="css/xtheme-gray.css" rel="stylesheet" type="text/css">
<!--<link rel="stylesheet" href="css/style.css" type="text/css" />-->

<form id="myAccountForm" name="myAccountForm" method="post" action="" onsubmit="return regformvalidation();">
<input type="hidden" name="mode" value="" />
	<table border="0" cellpadding="0" cellspacing="0" class="admob-Height" align="center">
	<tr>
	<td valign="top"><table border="0" align="center" cellpadding="0" cellspacing="0" class="admob-Height">
	<tr>
		<td width="244" valign="top"><?php include("left_pannel.php"); ?></td>
		<td width="14" valign="top">&nbsp;</td>
		<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
		<tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td width="14"><img src="images/admob-BoxTopLeftCor.jpg" alt="" width="14" height="14" /></td>
			<td class="admob-BoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="10" /></td>
			<td width="14"><img src="images/admob-BoxTopRightCor.jpg" alt="" width="14" height="14" /></td>
		</tr>
		</table></td>
		</tr>
		<tr>
		<td valign="top" class="admob-BoxMiddleBg"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
		<tr>
			<td width="600" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
			<tr>
			<td class="admob-SquareBoxTilteBg">Create Ad</td>
			</tr>
			<tr>
			<td valign="top" class="admob-SquareBoxBorder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-FormContent">
				<tr>
				<td width="162" height="25">Select Ad Type :</td>
				<td><select class="admob-FormDropDownBox" id="ad_type" name="ad_type" onchange="show_text_image()">
				<option value="text">Text</option>
	      			<option value="banner">Banner</option>
				</select></td>
				</tr>
				</table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="adText_module">
				<tr>
				<td height="20" class="admob-FormContent"><strong>Ad Text</strong></td>
				</tr>
				<tr>
				<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-FormContent">
				<tr id="row_alert_bidPrice" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_bidPrice" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>
				<tr>
					<td width="162" height="28">Enter Bid Price : </td>
					<td><input name="bid_price" id="bid_price" maxlength="30" type="text" class="admob-InputBoxsmallest" /></td>
				</tr>
				<tr id="row_alert_adName" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_adName" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>
				<tr>
					<td height="28">Ad Name : </td>
					<td><input name="ad_name" id="ad_name" maxlength="60" type="text" onkeyup="return preview_heading();" onkeyup="return preview_heading();"  class="admob-FromInputBox" /></td>
				</tr>
				<tr id="row_alert_adText" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_adText" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>
				<tr>
					<td valign="top">Ad Text :</td>
					<td valign="top"><textarea name="ad_text" class="admob-TextareaSmall" id="ad_text" rows="3" cols="35" onkeyup="return preview_text_description_func();"></textarea><br />
									<span class="admob-FormSmallContent">Use the %phn% tag to insert the user's phone modelinto the text<br /> 
	of your ad. (35 char max)</span></td>
				</tr>
					<tr>
					<td height="50" valign="top">Link To :</td>
								<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
				<td><input id="link_url_existing" checked="checked" name="link_url" value="existing" type="radio" onclick="show_destination_url(this.value)">
								An existing mobile page<br />
				<input id="link_url_lp" name="link_url" value="lp" type="radio" onclick="show_destination_url(this.value)">
								2 in 1 hosted Landing Page</td>
				</tr>
				
				<tr>
				<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr class="admob-FormContent" id="link_url_existing_div">
					<td height="28">Destination URL :</td>
					<td><input name="destinationUrl" id="destinationUrl" type="text" class="admob-FromInputBox" /></td>
				</tr>
				<?php
				$query_web = "select * from adspace_landing_page where UserId = ".$_SESSION[siteuserId]."";
				$res_web = mysql_query($query_web);
				?>
				<tr class="admob-FormContent">
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr class="admob-FormContent" id="link_url_existing_landing_page" style="display:none">
					<td valign="top">Landing URL: </td>
					<td valign="top"><select name="landing_url" id="landing_url" onchange="return una_dis(this.value);" class="admob-FormDropDownBox">
					<option value="select">Select</option>
                                    <?php while($row_web = mysql_fetch_array($res_web)){ ?>
                                    <option value="<?php echo $row_web['landingId']."-".$row_web['landing_url'] ?>"><?php echo $row_web['pageTitle']; ?></option>
                                    <?php } ?>
					</select><div id="link_url_lp_div" style="display: none;">
													You do not have any Landing Pages. <a href="create_landing_page.php">Create a new Landing Page</a>					</div></td>
				</tr>
				</table>
				</td>
				</tr>
				</table></td>
				</tr>
				</table></td>
				</tr>
				</table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="image_section" style="display:none">
                          <tr>
                            <td width="162" valign="top" class="admob-FormContent"><strong>Image (optional) :</strong></td>
                            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td class="admob-SquareBoxTilteBg1"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td class="admob-leftPanelWhiteContent">Images</td>
                                    <td align="right"><a href="#" class="admob-ImgToplink">Add or Edit Images</a></td>
                                  </tr>
                                </table></td>
                              </tr>
                              <tr>
                                <td valign="top" class="admob-SquareBoxBorder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td height="20" class="admob-BlueBoldContent">Upload new Image</td>
                                  </tr>
                                  <tr>
                                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td class="admob-FormBorder"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                              <tr>
                                               <!-- <td width="125" class="admob-FormContent"><strong>Browse an Image :</strong></td>-->
                                               <td>
						<input name="MAX_FILE_SIZE" value="75000" type="hidden">
						<span id="fileInput">
						<!--<input name="file" id="file" type="file" onchange="return submit_browse_form();">-->
					<iframe src="upload.php" align="top"  frameborder="0" scrolling="no" width="390px"  height="110px" allowtransparency="true"></iframe>
						</span>
							<inpUT type="hidden" name="sahara" value="11">
						<!--<input value="Upload" id="upload" type="submit">-->
  				  </td>
                                              </tr>
                                            </table></td>
                                          </tr>
                                          <tr>
                                            <td height="20" class="admob-FormSmallContent">(Allowed filetypes: *.jpg, *.jpeg, *.png) Upload size:(150 X 100)px</td>
                                          </tr>
                                        </table></td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                  <tr>
                                    <td><img src="images/spacer.gif" alt="" width="10" height="7" /></td>
                                  </tr>
                                  <tr>
                                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td class="admob-FormBorder"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-BlueBoldContent" id="imageSections">
                                          <tr>
                                            <td height="20">XL - 300x50</td>
                                          </tr>
                                          <tr>
                                            <td><img src="images/admob-300x50img.jpg" alt="" width="300" height="50" id="xl_img"  /><input name="xl_image_url" id="xl_image_url" class="image_url" type="hidden"></td>
                                          </tr>
                                          <tr>
                                            <td height="20">Large - 216x36</td>
                                          </tr>
                                          <tr>
                                            <td><img id="l_img"  src="images/admob-216x36img.jpg" alt="" width="216" height="36" /><input name="l_image_url" id="l_image_url" class="image_url" type="hidden"></td>
                                          </tr>
                                          <tr>
                                            <td height="20">Medium - 168x28</td>
                                          </tr>
                                          <tr>
                                            <td><img id="m_img"  src="images/admob-168x28img.jpg" alt="" width="168" height="28" /> <input name="m_image_url" id="m_image_url" class="image_url" type="hidden"></td>
                                          </tr>
                                          <tr>
                                            <td height="20">Small - 120x20</td>
                                          </tr>
                                          <tr>
                                            <td><img id="s_img"  src="images/admob-120x20img.jpg" alt="" width="120" height="20" /><input name="s_image_url" id="s_image_url" class="image_url" type="hidden"></td>
                                          </tr>
                                        </table></td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table></td>
                          </tr>
                        </table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
				<?php
				$SQL_country="select * from country";
				$EXE_country=mysql_query($SQL_country);
				?>
				<td width="162" valign="top" class="admob-FormContent"><strong>Select Targeting Country :</strong></td>
				<td valign="top"><select class="admob-LargeTextfield" name="country_mobile[]" id="country_mobile" multiple="true">
				<option value="" selected="selected">Select Country</option>
				<?php
				while($ROW_country=mysql_fetch_array($EXE_country))
				{
				?>
				<option value="<?php echo $ROW_country[countries_iso_code_2]; ?>"><?php echo $ROW_country[countryName]?></option>
				<?php
				}
				?>
				</select></td>
				</tr>
				</table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				 <td align="center"><input id="create_ad_submit" name="Submit22" type="button" class="admob-InputButton" value="Create Ad" onclick="create_ad()"/></td>
			</tr>
			</table></td>
			</tr>
			</table></td>
			<td width="11" valign="top">&nbsp;</td>
			<td width="302" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			<td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="text_preview">
			<tr>
				<td class="admob-SquareBoxTilteBg">Create Ad</td>
			</tr>
			<tr>
                                  <td align="center" id="prev_heading"></td>
                                </tr>

                                <tr>
                                  <td align="center" id="preview_text_description"></td>
                                </tr>
			<tr>
				<td class="admob-SquareBoxBorder admob-FormContent">Please note: The Preview will not display
	correctly if you do not set the "Text size" to 
	"Normal" on your browser.</td>
			</tr>
			</table></td>
			</tr>
			<tr>
			<td>&nbsp;</td>
			</tr>
			<tr>
			<td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="preview" style="display:none">
			<tr>
				<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
				<td><table border="0" cellspacing="0" cellpadding="0">
					<tr>
					<td width="29" id="Nav1" onclick="show_mobile_set(1)"><img src="images/admob-SButton.jpg" alt="" width="29" height="22" /></td>
					<td width="3">&nbsp;</td>
					<td width="29" id="Nav2" onclick="show_mobile_set(2)"><img src="images/admob-MButton.jpg" alt="" width="29" height="22" /></td>
					<td width="3" >&nbsp;</td>
					<td width="29" id="Nav3" onclick="show_mobile_set(3)"><img src="images/admob-LButton.jpg" alt="" width="29" height="22" /></td>
					<td width="3">&nbsp;</td>
					<td width="29" id="Nav4" onclick="show_mobile_set(4)"><img src="images/admob-XLButton.jpg" alt="" width="29" height="22" /></td>
					</tr>
				</table></td>
				</tr>
				<tr>
				<td><img src="images/spacer.gif" alt="" width="10" height="8"/></td>
				</tr>
				<tr>
				<td><img src="images/admob-300x50img.jpg" alt="" width="300" height="50" /></td>
				</tr>
				<tr>
				<td><img src="images/spacer.gif" alt="" width="10" height="8" /></td>
				</tr>
				</table></td>
			</tr>
	
			<tr class="preview_content selected" id="content_1" style="display:block; width:120; height:20">
				<td class="admob-FormContent"><strong>Mobile Website</strong><br />
			</td>
			</tr><tr  class="preview_content" id="content_2" style="display:none; width:168; height:28;"><TD class="admob-FormContent"><strong>Mobile Website</strong><br /></TD></tr><tr  class="preview_content" id="content_3" style="display:none; width:216; height:36;"><TD class="admob-FormContent"><strong>Mobile Website</strong><br /></TD></tr><tr  class="preview_content" id="content_4" style="display:none; width:300; height:50;"><TD class="admob-FormContent"><strong>Mobile Website</strong><br /></TD></tr>
			</table></td>
			</tr>
			</table></td>
		</tr>
		</table></td>
		</tr>
		<tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td width="14"><img src="images/admob-BoxBottomLeftCor.jpg" alt="" width="14" height="14" /></td>
			<td class="admob-BoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="10" /></td>
			<td width="14"><img src="images/admob-BoxBottomRightCor.jpg" alt="" width="14" height="14" /></td>
		</tr>
		</table></td>
		</tr>
		</table></td>
	</tr>
	</table></td>
	</tr>
	</table>
</form>
            
<?php

}
		?> 